import {
	SETINDEXDATA
} from './mutation-types.js'

const state = {
	indexData: {}
}
const mutations = {
	// 转大写:ctrl+shift+u
	[SETINDEXDATA](state, indexData) {
		// console.log('---------', indexData.categoryModule[0].itemList);
		state.indexData = indexData
	}
}
const getters = {}
const actions = {
	async getIndexData(context) {
		/* 
		  this->store对象,action函数的第一个实参是store对象的浅拷贝对象(context对象)
		 action其实可以越过mutation,直接更新Vuex的state数据
		 之所以不这么做,是因为Vue devtools只会记录触发了多少个mutation,在调试器内可能会无法拿到最新数据
		 
		 */
		const result = await this._vm.$request('/getIndexData')
		context.commit(SETINDEXDATA, result)
		// console.log(result)
	}
}
export default {
	namespaced: true,
	state,
	actions,
	mutations,
	getters

}
